package bilibili;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.io.*;

/**
 * @author ilongsay
 */
public class ReadFileGetName {
    public static String readFileContent(String fileName) {
        File file = new File(fileName);
        BufferedReader reader = null;
        String encoding = "UTF-8";
        StringBuilder sbf = new StringBuilder();
        try {
            reader = new BufferedReader(new InputStreamReader(
                    new FileInputStream(file),encoding));
            String tempStr;
            while ((tempStr = reader.readLine()) != null) {
                sbf.append(tempStr);
            }
            reader.close();
            JSONObject object = JSON.parseObject(sbf.toString());
            return object.get("PartName").toString();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
        return null;
    }
}
